package xinxin.com.BuilderPattern.Person;

import javax.swing.*;
import java.awt.*;

/**
 * @author ：史鑫鑫
 * @date ：Created in 2019/3/25 19:47
 */
public class PersonDirector {
    private PersonBuilder personBuilder;

    public PersonDirector(PersonBuilder personBuilder) {
        this.personBuilder = personBuilder;
    }

    public void CreatePerson() {
        JFrame jFrame = new JFrame();
        JPanel jpanel = new JPanel() {
            // 重写paint方法
            @Override
            public void paint(Graphics graphics) {
                // 必须先调用父类的paint方法
                super.paint(graphics);
                graphics.setColor(personBuilder.getColor());
                // 用画笔Graphics，在画板JPanel上画一个小人
                personBuilder.BuildHead(graphics);
                personBuilder.BuildBody(graphics);
                personBuilder.BuildArmLeft(graphics);
                personBuilder.BuildArmRight(graphics);
                personBuilder.BuildLegLeft(graphics);
                personBuilder.BuildLegRight(graphics);
            }
        };
        jFrame.add(jpanel);
        // 设置画框大小（宽度，高度），默认都为0
        jFrame.setSize(300, 300);
        // 将画框展示出来。true设置可见，默认为false隐藏
        jFrame.setVisible(true);
    }
}
